package com.x.service.student;

import com.x.bean.Achievement;
import com.x.bean.User;
import com.x.dao.BaseDao;
import com.x.dao.student.StudentDao;
import com.x.dao.student.StudentDaoImpl;

import java.sql.Connection;
import java.util.List;

/**
 * @author 13925
 */
public class StudentServiceImpl implements StudentService {

    private StudentDao studentDao;

    public StudentServiceImpl() {
        studentDao = new StudentDaoImpl();
    }


    @Override
    public boolean updateStudent(User user) {
        Connection connection = null;
        boolean flag = false;
        try {
            connection = BaseDao.getConnection();
            int updateRows = studentDao.updateStudent(connection, user);
            if (updateRows > 0) {
                flag = true;
                System.out.println("update 成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("update 失败!");
        } finally {
            BaseDao.closeResource(connection, null, null);
        }
        return flag;
    }

    @Override
    public List<Achievement> getStudentByCode(String code) {
        Connection connection = null;
        //通过业务层调用对应的具体数据库操作
        List<Achievement> achievementsList = null;
        try {
            connection = BaseDao.getConnection();
            achievementsList = studentDao.getAchievementByCode(connection, code);
        } catch (Exception e) {
            e.printStackTrace();
            achievementsList = null;
        } finally {
            BaseDao.closeResource(connection, null, null);
        }
        return achievementsList;
    }
}
